package run.newbug.jt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import run.newbug.jt.service.FileService;
import run.newbug.jt.vo.ImageVO;
import run.newbug.jt.vo.SysResult;

@RestController
@RequestMapping("/file")
@CrossOrigin
public class FileController {
    @Autowired
    private FileService fileService;

   @PostMapping("/upload")
    public SysResult upload(MultipartFile file){
       ImageVO imageVO = fileService.upload(file);
       if (imageVO == null){
           return SysResult.fail();
       }
       return SysResult.succe(imageVO);
    }

    @DeleteMapping("deleteFile")
    public SysResult deleteFile(String virtualPath){
       fileService.deleteFile(virtualPath);
       return SysResult.succe();
    }
}
